#!/bin/bash

# 环境变量检查脚本

echo "======================================"
echo "  检查环境变量配置"
echo "======================================"
echo ""

echo "腾讯云OSS环境变量:"
echo "  TENCENT_SECRET_ID: ${TENCENT_SECRET_ID:0:8}..."
echo "  TENCENT_SECRET_KEY: ${TENCENT_SECRET_KEY:0:8}..."
echo "  TENCENT_BUCKET: '$TENCENT_BUCKET'"
echo "  TENCENT_REGION: '$TENCENT_REGION'"
echo ""

echo "阿里云OSS环境变量:"
echo "  ALIYUN_ACCESS_KEY_ID: ${ALIYUN_ACCESS_KEY_ID:0:8}..."
echo "  ALIYUN_ACCESS_KEY_SECRET: ${ALIYUN_ACCESS_KEY_SECRET:0:8}..."
echo "  ALIYUN_BUCKET: '$ALIYUN_BUCKET'"
echo "  ALIYUN_REGION: '$ALIYUN_REGION'"
echo ""

# 检查是否为空
check_var() {
    local var_name="$1"
    local var_value="${!var_name}"

    if [ -z "$var_value" ]; then
        echo "❌ $var_name 未设置"
        return 1
    else
        echo "✅ $var_name 已设置"
        return 0
    fi
}

echo "变量检查结果:"
tencent_ok=true
aliyun_ok=true

if ! check_var "TENCENT_SECRET_ID" || \
   ! check_var "TENCENT_SECRET_KEY" || \
   ! check_var "TENCENT_BUCKET" || \
   ! check_var "TENCENT_REGION"; then
    tencent_ok=false
fi

if ! check_var "ALIYUN_ACCESS_KEY_ID" || \
   ! check_var "ALIYUN_ACCESS_KEY_SECRET" || \
   ! check_var "ALIYUN_BUCKET" || \
   ! check_var "ALIYUN_REGION"; then
    aliyun_ok=false
fi

echo ""
if [ "$tencent_ok" = true ]; then
    echo "✅ 腾讯云OSS配置完整"
else
    echo "❌ 腾讯云OSS配置不完整"
fi

if [ "$aliyun_ok" = true ]; then
    echo "✅ 阿里云OSS配置完整"
else
    echo "❌ 阿里云OSS配置不完整"
fi

echo ""
echo "如何设置环境变量:"
echo ""
echo "方法1 - 在当前shell中设置:"
echo "export TENCENT_SECRET_ID='你的SecretID'"
echo "export TENCENT_SECRET_KEY='你的SecretKey'"
echo "export TENCENT_BUCKET='你的存储桶名称'"
echo "export TENCENT_REGION='ap-beijing'"
echo ""
echo "方法2 - 创建 .env 文件:"
echo "cat > .env << EOF"
echo "TENCENT_SECRET_ID='你的SecretID'"
echo "TENCENT_SECRET_KEY='你的SecretKey'"
echo "TENCENT_BUCKET='你的存储桶名称'"
echo "TENCENT_REGION='ap-beijing'"
echo "EOF"
echo "source .env"